//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows;
using System.Windows.Controls;

namespace OpenLS.Spreadsheet.UI.Internals
{
    class InvertedStackPanel: StackPanel
    {
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            UIElementCollection children = Children;
            bool flag = Orientation == System.Windows.Controls.Orientation.Horizontal;
            Rect finalRect = new Rect(arrangeSize);
            double width = 0.0;
            int num2 = children.Count - 1;
            int count = children.Count;
            while (num2 >= 0)
            {
                UIElement element = children[num2];
                if (element != null)
                {
                    if (flag)
                    {
                        finalRect.X += width;
                        width = element.DesiredSize.Width;
                        finalRect.Width = width;
                        finalRect.Height = Math.Max(arrangeSize.Height, element.DesiredSize.Height);
                    }
                    else
                    {
                        finalRect.Y += width;
                        width = element.DesiredSize.Height;
                        finalRect.Height = width;
                        finalRect.Width = Math.Max(arrangeSize.Width, element.DesiredSize.Width);
                    }
                    element.Arrange(finalRect);
                }
                num2--;
            }
            return arrangeSize;
        }




    }
}
